<?php
/**
 * requestshift Function
 *
 * Return available shifts.
 *
 * @author Manas Kalucha <manaskalucha@gmail.com>
 */
include_once 'UTcheckAuth.php';
include_once 'UTerrorcode.php';
include_once 'UTcheckAuth.php';
include_once 'UTDBGlobal.php';
/**
 * @param $userName string
 * @param $userPassHash string
 * @param $desiredShift string
 * @return array
 */
function requestShift($userName, $userPassHash,$desiredShift)
{
	global $dbaddress;
    global $dbuser;
    global $dbpassword;
    global $dbdatabasename;

	if (checkAuthentication($userName, $userPassHash) == true)
	{
		$r = array();
		$conn = new mysqli($dbaddress,$dbuser,$dbpassword,$dbdatabasename);
		$shift = json_decode($desiredShift, true);
		$sql = "SELECT * FROM roledate WHERE roleID = '".$shift['RoleID']."' AND empID='".$shift['EmpID']."' AND dateID = '".$shift['DateID']."'";
		$result = $conn->query($sql);

		if($result->num_rows>0)
		{
			while($row = $result->fetch_assoc())
			{
				$r[count($r)]= array('shiftStatus'=>$row['shiftStatus']);
			}
			$error = ErrorCode::successRead;
			$output = array('code' => $error, 'value' => $r);
		}
		$conn->close();
	}
	else
	{
		$error = ErrorCode::authFailRead;
		$output = array('code' => $error);
	}
	return $output;
}

//Test Code
// $a = array('RoleID' => 1 , 'EmpID' =>1, 'DateID' => 1);
// $r = requestShift('user','pass',json_encode($a));
// print_r($r);

?>
